package ngat.oss.simulation;

import java.io.*;
import java.util.*;

import ngat.phase2.*;

public class BasicMemoryPhase2Model implements Phase2Model, Serializable {

    /** Set of proposals.*/
    private Map proposals;

    /** Root name of model.*/
    private String rootName;

    /** Create a BasicMemoryPhase2Model.*/
    public BasicMemoryPhase2Model() {
	proposals = new HashMap();
    }

    /** Create a BasicMemoryPhase2Model with given root name.*/
    public BasicMemoryPhase2Model(String rootName) {
	this();
	this.rootName = rootName;
    }
    
    /** Returns the model's root name.*/
    public String getRootName() throws Exception { return rootName; }

    /** Returns an iterator over the list of proposals.*/
    public Iterator listProposals() throws Exception {
	return proposals.values().iterator();
    }
    
    /** Get a specific proposal. If not present return null.*/
    public Proposal getProposal(String path) throws Exception {
	return (Proposal)proposals.get(path);
    }
    
    /** Add a new proposal, or replcae.*/
    public void addProposal(Proposal proposal) throws Exception {
	String path = proposal.getFullPath();
	System.err.println("BMP2M::Adding proposal: "+path);
	proposals.put(proposal.getFullPath(), proposal);
    }
    
    /** Delete a proposal.*/
    public void removeProposal(Proposal proposal) throws Exception {
	proposals.remove(proposal.getFullPath());
    }

    /** Clear out all proposals.*/
    public void clear() throws Exception {
	proposals.clear();
    }

}
